﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="App.xaml.cs" company="arvystate.net">
//   arvystate.net
// </copyright>
// <summary>
//   Interaction logic for App.xaml
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace PresentationAid
{
    using System;
    using System.AutoUpdate.Managers;
    using System.AutoUpdate.Sources;
    using System.Windows;

    using NLog;

    using PresentationAid.Core;
    using PresentationAid.Settings;

    /// <summary>
    /// Interaction logic for App
    /// </summary>
    public partial class App
    {
        #region Static Fields

        /// <summary>
        /// The logger.
        /// </summary>
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

        #endregion

        #region Methods

        /// <summary>
        /// The application exit.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void ApplicationExit(object sender, ExitEventArgs e)
        {
            Logger.Info("Event: ApplicationExit - CloseKinect");

            KinectSensorManager.Instance.CloseKinect();

            Logger.Trace("EventDetail: ApplicationExit - DisposeKinect");

            KinectSensorManager.Instance.Dispose();
        }

        /// <summary>
        /// The application startup.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void ApplicationStartup(object sender, StartupEventArgs e)
        {
            Logger.Info("Event: ApplicationStartup");

            SettingManager.Instance.LoadSettings();

            // Setup AutoUpdater
            Logger.Trace("EventDetail: ApplicationStartup - AutoUpdate");

            SourceManager.Instance.Sources.Add(
                new TextWebSource("http://www.arvystate.net/update/PresentationAid", "versionList", "get"));

            UpdateManager.Instance.Clean();

            Logger.Debug("Event: ApplicationStartup - CheckForUpdate: {0}", SettingManager.Instance.AutoUpdate);

            if (SettingManager.Instance.AutoUpdate)
            {
                SettingManager.Instance.LastUpdateCheck = DateTime.Now.Ticks;

                UpdateManager.Instance.CheckForUpdates();
            }
        }

        #endregion
    }
}